<?php
    class blog_m extends Model{
        function Blog_m(){
            parent::Model();
            $this->load->database();
        }
        function get_all_blogs($per_page,$off_set){
            $this->db->select('lehu_profiles.display_name,lehu_profiles.user_id,seating_blog.id ,seating_blog.name,seating_blog.description,seating_blog.blog_date,seating_blog.image');
            $this->db->from('seating_blog,lehu_profiles');
            $this->db->where('seating_blog.user_id = lehu_profiles.user_id');  
            $this->db->order_by('id','desc');
            $this->db->limit($per_page,$off_set);
            return $this->db->get()->result_array();
        }
      
        function add_blog($data)
        {
            $query=$this->db->insert('seating_blog',$data);
            return $query;
        }
        function get_blog_by_id($id)
        {
            $this->db->select();
            $this->db->from('seating_blog');
            $this->db->where('id',$id);
            return $this->db->get();
        }
        function add_comment($data)
        {
            $query=$this->db->insert('seating_comment',$data);
            return $query;
        }
        function get_comment_by_blog_id($blog_id,$per_page,$off_set)
        {
            $this->db->select('lehu_profiles.display_name,lehu_profiles.user_id,lehu_profiles.gravatar, seating_comment.id as id_comment,
            seating_comment.content, seating_comment.comment_date, seating_blog.id as id_blog,seating_blog.name');
            $this->db->from('seating_comment, seating_blog, lehu_profiles');
            $this->db->where('seating_comment.blog_id = seating_blog.id');
            $this->db->where('seating_comment.user_id = lehu_profiles.user_id');    
            $this->db->where('seating_comment.blog_id ',$blog_id);
            $this->db->order_by('seating_comment.id desc');
            $this->db->limit($per_page,$off_set);
            return $this->db->get()->result_array();
        }
        function count_comment($blog_id){
            $this->db->select( );
            $this->db->from('seating_comment');
            $this->db->where('seating_comment.blog_id ',$blog_id);
            $this->db->order_by('seating_comment.id desc');
            return count($this->db->get()->result_array());
        }
        function update_blog($data,$id)
        {
            return $this->db->update('seating_blog',$data,array('id'=>$id));
        }
    }
?>
